package Task1.Threading;

import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import Task1.model.DongCat;
import Task1.model.XeCat;

public class InThread implements Runnable {
    private Logger log = LoggerFactory.getLogger(InThread.class);
    private List<Thread> listThrXeDen;
    private XeCat xeIn;

    public InThread(int soXe, DongCat dongcat, int time) {
        listThrXeDen = new ArrayList<Thread>();
        for (int i = 0; i < soXe; i++) {
            xeIn = new XeCat(true, 0);
            xeIn.set_dongcat(dongcat);
            xeIn.setTime(time);
            Thread thrIn = new Thread(xeIn);          
            log.info("{} created! ", thrIn);
            listThrXeDen.add(thrIn);
            log.info("added {} to list {}", thrIn, listThrXeDen);            
        }
        return;
    }

    public void run() {
        for (Thread thrIn : listThrXeDen) {
            if (!thrIn.isAlive()) {
                thrIn.start();
                log.info("{} is started.",thrIn);
            }

        }
    }
}
